package com.thunder.soft.ui.adapter;

import android.content.Intent;
import android.view.View;

import androidx.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.thunder.soft.R;
import com.thunder.soft.bean.ProjectDetailsBean;
import com.thunder.soft.common.base.BaseAdapter;
import com.thunder.soft.common.base.BaseViewHolder;
import com.thunder.soft.databinding.ProjectDetailsItemBinding;
import com.thunder.soft.ui.activity.DetailsActivity;
import com.thunder.soft.vm.ProjectViewModel;

import java.util.List;

public class ProjectDetailsAdapter extends BaseAdapter<ProjectDetailsBean, ProjectDetailsItemBinding> {

    private ProjectViewModel projectViewModel;
    private static final String TAG = ProjectDetailsAdapter.class.getName();

    public void setProjectViewModel(ProjectViewModel projectViewModel) {
        this.projectViewModel = projectViewModel;
    }

    @Override
    protected int layoutId(int viewType) {
        return R.layout.project_details_item;
    }

    @Override
    protected void onBindHolder(ProjectDetailsItemBinding binding, @NonNull BaseViewHolder<ProjectDetailsItemBinding> holder,
                                int position, @NonNull ProjectDetailsBean data, List<Object> payloads) {
        super.onBindHolder(binding, holder, position, data, payloads);
        binding.setProjectDetailsBean(getData(position));
        binding.setProjectViewModel(projectViewModel);
        binding.executePendingBindings();

        Glide.with(getContext())
                .load(data.getEnvelopePic())
                .into(holder.getBinding().image);

        binding.projectItem.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(v.getContext(), DetailsActivity.class);
                intent.putExtra("link", getData(position).getLink());
                v.getContext().startActivity(intent);
            }
        });
    }
}